<template>
  <div v-loading="loading">
    <tableComponents :pagination="{ currentPage, pageSize, total: list.all_num }" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" @sendUserSearch="getSearch" :searchData="userSearchData" :isHaveExport="false" :isHaveAdd="false">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" stripe header-row-class-name="head_color" tooltip-effect="dark" style="width: 99.8%">
          <el-table-column label="群头像" min-width="100">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="群信息" min-width="150">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>群标题：</span>
                  <span>{{scope.row.title || '----'}}</span>
                </div>
                <div>
                  <span>IM：</span>
                  <span>{{scope.row.im || '----'}}</span>
                </div>
                <div>
                  <span>群聊人数：</span>
                  <span>{{scope.row.team_num || '----'}}</span>
                </div>
                <div>
                  <span>群消费人数：</span>
                  <span>{{scope.row.consumption || '----'}}</span>
                </div>
                <div>
                  <span>创建时间：</span>
                  <span>{{scope.row.created_time |getTimeFormat}}</span>
                </div>

              </div>
            </template>
          </el-table-column>
          <el-table-column label="创建人头像" min-width="100">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.boss_avatar)" alt />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="创建人信息" min-width="150">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>用户昵称：</span>
                  <span>{{scope.row.boss_nickname || '----'}}</span>
                </div>
                <div>
                  <span>会员账号：</span>
                  <span>{{scope.row.boss_username ||'---'}}</span>
                </div>

              </div>
            </template>
          </el-table-column>
          <el-table-column label="全员禁言" min-width="100">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.is_qyjy" active-color="#1aad19" inactive-color="#ffffff" active-text="on" inactive-text="off" active-value="1" @change="change_speak($event, scope.row, 'is_qyjy')" inactive-value="0"></el-switch>
            </template>
          </el-table-column>
          <!-- <el-table-column label="开放加入" min-width="100" size="mini">
            <template slot-scope="scope">
              <el-select v-model="scope.row.is_open" placeholder="请选择" @change="change_switch($event,scope.row,'is_open')">
                <el-option label="开放加入" value="1"> </el-option>
                <el-option label="禁止加入" value="2"> </el-option>
                <el-option label="申请加入" value="0"> </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="开放公聊" min-width="100">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.is_chat" active-color="#1aad19" inactive-color="#ffffff" active-text="on"
                  inactive-text="off" active-value="1" @change="change_switch($event, scope.row, 'is_chat')" inactive-value="0"></el-switch>
            </template>
          </el-table-column>

          <el-table-column label="允许发红包" min-width="100">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.is_hair_red" active-color="#1aad19" inactive-color="#ffffff" active-text="on"
                  inactive-text="off" active-value="1" @change="change_switch($event, scope.row, 'is_hair_red')" inactive-value="0"></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="禁成员抢红包" min-width="100">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.is_red" active-color="#1aad19" inactive-color="#ffffff" active-text="on"
                  inactive-text="off" active-value="1" @change="change_switch($event, scope.row, 'is_red')" inactive-value="0"></el-switch>
            </template>
          </el-table-column>
        <el-table-column label="成员保护" min-width="100">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.is_protect" active-color="#1aad19" inactive-color="#ffffff" active-text="on"
                  inactive-text="off" active-value="1" @change="change_switch($event, scope.row, 'is_protect')" inactive-value="0"></el-switch>
            </template>
          </el-table-column>

          <el-table-column label="激活" min-width="100">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.is_show" active-color="#1aad19" inactive-color="#ffffff" active-text="on"
                  inactive-text="off" active-value="1" @change="change_show($event, scope.row, 'is_show')" inactive-value="0"></el-switch>
            </template>
          </el-table-column> -->

          <el-table-column label="操作" align="left" min-width="250">
            <template slot-scope="scope">
              <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="gotoDetail(scope.row.id,1)">查看群聊人员</el-button>
              <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="gotoDetail(scope.row.id,2)">群红包</el-button>
              <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="gotoDetail(scope.row.id,3)">公排关系</el-button>
              <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="gotoDetail(scope.row.im,4)">聊天记录</el-button>
              <!-- <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="getRecordInfo(scope.row.id)">查看打卡记录</el-button> -->
              <!-- <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="showEditDialog(scope.row.id, scope.row.boss_username)">
                更换群主</el-button>
              <el-button :loading="$store.state.isLoading" type="danger" size="mini" @click="delBtn(scope.row.id)">
                删除
              </el-button> -->
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>
    <imteamEdit @parent="reload" :show.sync="show" :rechargeId="rechargeId"></imteamEdit>
  </div>
</template>
<script>
import imteamEdit from "@/components/imteam/teamEdit.vue";
import { imteamSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data() {
    return {
      userSearchData: imteamSearchData,
      show: false,
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      rechargeId: "",
      searchAll: {},
    };
  },
  components: {
    imteamEdit,
  },
  methods: {
    gotoDetail(id, type) {
      sessionStorage.setItem("title", this.$store.state.title);
      sessionStorage.setItem("parentTitle", this.$store.state.parentTitle);
      if (type == 1) {
        let routeData = this.$router.resolve({
          path: "/index/imteam/groupUserList",
          query: { id: id },
        });
        window.open(routeData.href, "_blank");
      } else if (type == 2) {
        let routeData = this.$router.resolve({
          path: "/index/dz/red_list",
          query: { mid: id },
        });
        window.open(routeData.href, "_blank");
      } else if (type == 3) {
        let routeData = this.$router.resolve({
          path: "/index/page/platoon_detail",
          query: { mid: id },
        });
        window.open(routeData.href, "_blank");
      } else if (type == 4) {
        let routeData = this.$router.resolve({
          path: "/index/imteam/messageList",
          query: { im: id, is_c2c: 1 },
        });
        window.open(routeData.href, "_blank");
      }
    },
    delBtn(id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          this.$api.getIMteam.im_team_del({ id: id }).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.getNewsAll();
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    },
    getUserInfo(id) {
      sessionStorage.setItem("title", this.$store.state.title);
      sessionStorage.setItem("parentTitle", this.$store.state.parentTitle);
      let routeData = this.$router.resolve({
        path: "/index/imteam/groupUserList",
        query: { id: id },
      });
      window.open(routeData.href, "_blank");
    },

    getRecordInfo(id) {
      this.$store.commit("addbreadcrumbs", {
        title: "查看打卡记录",
        url: `/index/imteam/checkRecord?id=${id}`,
      });
      this.$router.push({
        path: "/index/imteam/checkRecord",
        query: { id: id },
      });
    },

    showEditDialog(id) {
      this.show = true;
      this.rechargeId = id;
    },
    reload() {
      this.getNewsAll(this.searchAll);
    },
    getSearch(obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      this.$api.getIMteam.getIMteamList(params).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },
    change_show(val, row, type) {
      var params = {};
      params.id = row.id;
      params[type] = val;
      this.$api.getIMteam.getIMteamlock(params).then((res) => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess(res.data.result);
        } else {
          this.$fnc.alertError(res.data.result);
        }
      });
    },
    change_switch(val, row, type) {
      var params = {};
      params.id = row.id;
      params[type] = val;
      this.$api.getIMteam.editIMteam(params).then((res) => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess(res.data.result);
        } else {
          this.$fnc.alertError(res.data.result);
        }
      });
    },

    change_speak(val, row, type) {
      var params = {};
      params.id = row.id;
      params[type] = val;
      this.$api.getDz.set_team_speak(params).then((res) => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess(res.data.result);
        } else {
          this.$fnc.alertError(res.data.result);
          this.getNewsAll();
        }
      });
    },
  },
  beforeCreate() {},
  created() {
    this.getNewsAll();
  },
  computed: {},
  watch: {
    getAdminuserList(obj) {
      this.list = obj.data;
      this.pageSize = parseInt(obj.page_size);
      this.currentPage = parseInt(obj.page);
      this.allPage = obj.all_page;
      this.allNum = obj.all_num;
    },
  },
};
</script>

<style lang="less" scoped>
thead > tr > th {
  height: 45px;
  line-height: 45px;
}
td,
th {
  border: 1px solid #e1e3e4;
  font-size: 12px;
}
th {
  background: #f8f8f8;
  font-weight: normal;
  color: #323437;
}
td {
  height: 75px;
  color: #000;
}
.caozuo {
  padding-left: 50px;
}
.pl {
  padding-left: 15px;
}
.chkBox {
  display: block;
  margin: 0 auto;
  width: 18px;
  height: 18px;
  background: #fff;
}
.aBtn_1 {
  padding: 10px;
}
</style>
